package com.heima.kafka.boot.listener;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * 消费者侦听器
 *
 * @author DiXiaoNie
 * @date 2022/12/28
 * @since 2022/12/28 16:20
 */

@Component
public class ConsumerListener {


    /**
     * 得到消息
     *
     * @param consumerRecord 消费记录
     * @author DiXiaoNie
     * @date 2023/01/07
     */
    @KafkaListener(topics = {"kafka-stream-consumer"})
    public void getMessage(ConsumerRecord consumerRecord) {
        System.out.println(consumerRecord.key().toString() + ":" + consumerRecord.value());
    }



    /**
     * 得到消息
     *
     * @author DiXiaoNie
     * @date 2022/12/28
     */
    //可以监听多个
/*    @KafkaListener(topics = "boot-topic")
    public void getMessage(String message) {
        Map map = JSON.parseObject(message, Map.class);
        System.out.println("消息内容为：" + map);
    }*/
}
